package Hot100.BackTracking;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class combine {
    public static void main(String[] args) {
        System.out.println(new combine().combine(4,3));
    }
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        back(n,1,k);
        return result;
    }
    public void back(int n ,int startIndex, int k){
        if(path.size() == k){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i <= n - (k - path.size()) + 1; i++) {
            path.add(i);
            back(n,i+1,k);
            path.removeLast();
        }
    }
}
